package io.yuncheng.modules.sys.controller;

import io.yuncheng.common.utils.R;
import io.yuncheng.modules.job.service.ScheduleJobService;
import io.yuncheng.modules.job.task.AppLogArithmeticTask;
import io.yuncheng.modules.job.task.SyncApplicationTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 提供外部接口不用登陆
 *
 * @author jared
 * @email 15721509625@163.com
 * @date 2020-10-29 18:50:09
 */
@RestController
@Api(tags = "测试")
@RequestMapping("test")
public class TestController {

    @Resource
    private SyncApplicationTask syncApplicationTask;
    @Resource
    private AppLogArithmeticTask appLogArithmeticTask;
    @Resource
    private ScheduleJobService scheduleJobService;
    @Resource
    private ApplicationContext applicationContext;

    @ApiOperation("任务调用")
    @PostMapping("/sync")
    public R deptList() {
        syncApplicationTask.run("{}");
        return R.ok();
    }
    @ApiOperation("任务调用")
    @PostMapping("/collect-app-log")
    public R collectLog() {
        appLogArithmeticTask.run("{}");
        return R.ok();
    }
    @ApiOperation("任务调用")
    @PostMapping("/job-list-test")
    public R testExe() throws Exception {
        applicationContext.getBean("");
        ClassPathResource classPathResource = new ClassPathResource("beans.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        reader.loadBeanDefinitions(classPathResource);
        return R.ok().put("data", scheduleJobService.list());
    }

}
